package unq.edu.cui.tp.arena;

import org.uqbar.arena.actions.MessageSend;
import org.uqbar.arena.layout.ColumnLayout;
import org.uqbar.arena.layout.HorizontalLayout;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.widgets.tables.Column;
import org.uqbar.arena.widgets.tables.Table;
import org.uqbar.arena.windows.SimpleWindow;
import org.uqbar.arena.windows.WindowOwner;

import unq.edu.cui.tp.dominio.Asignacion;
import unq.edu.cui.tp.dominio.Planificacion;
import unq.edu.cui.tp.modelo.ventanas.BooleanToPlanificadaONoTransformer;
import unq.edu.cui.tp.modelo.ventanas.PlanificarSemana;
import unq.edu.cui.tp.modelo.ventanas.PlanificarUnaFecha;
import unq.edu.cui.tp.modelo.ventanas.VerHorario;

public class PlanificarSemanaWindow extends SimpleWindow<PlanificarSemana> {

	public PlanificarSemanaWindow(WindowOwner parent, PlanificarSemana model) {
		
		super(parent, model);
	}
	@Override
	protected void addActions(Panel actionsPanel) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void createFormPanel(Panel mainPanel) {
		
		this.setTitle("Planificaciones de la semana");
		this.setTaskDescription("Planificaciones");
		
		Panel form = new Panel(mainPanel);
		form.setLayout(new ColumnLayout(2));
		
		this.createGrid(mainPanel);
		this.createGridActions(mainPanel);

	}
	
	protected void createGrid(Panel mainPanel) {
			
			Table<Planificacion> table = new Table<Planificacion>(mainPanel, Planificacion.class);
			table.setHeigth(200);
			table.setWidth(450);
	
			table.bindItemsToProperty("sistema.planificaciones");
			table.bindValueToProperty("planificacionSeleccionada");
	
			this.describeGrid(table);
		}
	
	protected void describeGrid(Table<Planificacion> table) {
		new Column<Planificacion>(table)
			.setTitle("Fecha")
			.setFixedSize(250)
			.bindContentsToProperty("fechaSimple");

		
		new Column<Planificacion>(table)

			.setTitle("Estado")
			.setFixedSize(200)
			.bindContentsToTransformer(new BooleanToPlanificadaONoTransformer());

	}

	protected void createGridActions(Panel mainPanel) {
		Panel actionsPanel = new Panel(mainPanel);
		actionsPanel.setLayout(new HorizontalLayout());
		
		new Button(actionsPanel).setCaption("Planificar").onClick(new MessageSend(this, "planificar"));
		
		new Button(actionsPanel).setCaption("Ver horarios").onClick(new MessageSend(this, "verHorario"));
	}
	
	
	//Acciones de botones
	public void verHorario(){
		new VerHorarioWindow(this, new VerHorario(this.getModelObject().getPlanificacionSeleccionada())).open();
	}
	
	public void planificar(){
		new PlanificarUnaFechaWindow(this, new PlanificarUnaFecha(this.getModelObject().getSistema(), this.getModelObject().getPlanificacionSeleccionada())).open();
	}
}
